package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.BaseAttributeService;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.vo.album.CategoryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@SuppressWarnings({"unchecked", "rawtypes"})
public class BaseCategoryApiController {
	
	@Autowired
	private BaseCategoryService baseCategoryService;

	@Autowired
	private BaseAttributeService baseAttributeService;

	// http://localhost:8500/api/album/category/getBaseCategoryList
	@Operation(summary = "获取分类列表")
	@GetMapping("/getBaseCategoryList")
	public Result getBaseCategoryList() {
		List<CategoryVo> baseCategoryList = baseCategoryService.getBaseCategoryList();
		return Result.ok(baseCategoryList);
	}

	// http://localhost:8500/api/album/category/findAttribute/2
	@Operation(summary = "根据分类id获取分类信息")
	@GetMapping("/findAttribute/{categoryId}")
	public Result findAttribute(@PathVariable Long categoryId) {
		List<BaseAttribute> baseAttributeList  = baseAttributeService.findAttribute(categoryId);
		return Result.ok(baseAttributeList);
	}

	// http://localhost:8500/api/album/category/findTopBaseCategory3/1
	@Operation(summary = "根据一级分类id获取三级分类信息")
	@GetMapping("/findTopBaseCategory3/{category1Id}")
	public Result findTopBaseCategory3(@PathVariable Long category1Id) {
		List<BaseCategory3> category3List = baseCategoryService.findTopBaseCategory3(category1Id);
		return Result.ok(category3List);
	}

	// http://localhost:8500/api/album/category/getBaseCategoryList/1
	@Operation(summary = "根据一级分类id获取一级分类和二级分类和三级分类信息")
	@GetMapping("/getBaseCategoryList/{category1Id}")
	public Result getBaseCategoryResult(@PathVariable Long category1Id) {
		CategoryVo category = baseCategoryService.getBaseCategoryResult(category1Id);
		return Result.ok(category);
	}


}

